home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / xpk_source / xpkmaster / sublibs.c < prev    next >
C/C++ Source or Header  |  1998-08-27  |  2KB  |  88 lines

  1. #ifndef XPKMASTER_SUBLIBS_C
  2. #define XPKMASTER_SUBLIBS_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        sublibs.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: sublibs.c 1.3 (26.03.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Handling of xpksublibraries
  12.  
  13.  1.0   09.10.96 : first real version
  14.  1.1   19.12.97 : a bit code cleanup
  15.  1.2   09.01.98 : included idfromname from util.c
  16.  1.3   26.03.98 : a little bug fix, internal toupper function
  17. */
  18.  
  19. #include <proto/exec.h>
  20. #include <proto/xpksub.h>
  21. #include <exec/types.h>
  22. #include <dos/dos.h>
  23. #include "xpkmaster.h"
  24. #include "texts.h"
  25. #include "version.h"
  26.  
  27. /************************* open sublib from ID ***************************/
  28. XPK_ALLINONE struct Library *opensub(struct XpkBuffer *xbuf, ULONG ID)
  29. {
  30.   struct Library *XpkSubBase;
  31.   UBYTE libname[SUBLIBNAME_SIZE];
  32.  
  33.   /* Do nothing if we already have what we want */
  34.   if((xbuf->xb_SubBase) && (xbuf->xb_SubID == ID))
  35.     return xbuf->xb_SubBase;
  36.  
  37.   closesub(xbuf);
  38.  
  39.   xbuf->xb_SubID = ID;
  40.   sprintf(libname, SUBLIBNAME_STRING, &xbuf->xb_SubID);
  41.  
  42.   if(!(xbuf->xb_SubBase = XpkSubBase = OpenLibrary(libname, 0)))
  43.     xbuf->xb_Result = XPKERR_MISSINGLIB;
  44.   else if((xbuf->xb_SubInfo = XpksPackerInfo())->xi_MasterVersion > VERSION)
  45.   {
  46.     xbuf->xb_Result = XPKERR_OLDMASTLIB;
  47.     closesub(xbuf);
  48.   }
  49.   return xbuf->xb_SubBase;
  50. }
  51.  
  52. /*********************** close any open sub-library *********************/
  53. XPK_ALLINONE void closesub(struct XpkBuffer *xbuf)
  54. {
  55.   if(xbuf->xb_SubBase)
  56.   {
  57. #ifdef DEBUG
  58.     DebugRunTime("closesub: closing lib %.4s", &xbuf->xb_SubID);
  59. #endif
  60.     CloseLibrary(xbuf->xb_SubBase);
  61.     xbuf->xb_SubBase = 0;
  62.   }
  63. }
  64.  
  65. /********************** get ID number from string ***********************/
  66.  
  67. static UBYTE xpkupper(UBYTE c)
  68. {
  69.   if(c >= 'a' && c <= 'z')
  70.     c -= 'a'-'A';
  71.   return c;
  72. }
  73.  
  74. XPK_ALLINONE ULONG idfromname(STRPTR name)
  75. {
  76.   ULONG i, j=0;
  77.  
  78.   for(i = 4; i; i--)
  79.   {
  80.     j <<= 8;
  81.     j += xpkupper(*(name++));
  82.   }
  83.  
  84.   return j;
  85. }
  86.  
  87. #endif /* XPKMASTER_SUBLIBS_C */
  88.